package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.annotation.TingshuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserListenProcess;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

	//Request URL: http://localhost:8500/api/user/userListenProcess/getTrackBreakSecond/6447

	@TingshuLogin
	@GetMapping("/getTrackBreakSecond/{trackId}")
	@Operation(summary = "获取声音播放进度")
	public Result getTrackBreakSecond(@PathVariable(value = "trackId") Long trackId){
		Long userId = AuthContextHolder.getUserId();
		BigDecimal trackBreakSecond =  userListenProcessService.getTrackBreakSecond(trackId,userId);
		return Result.ok(trackBreakSecond);
	}


	//Request URL: http://localhost:8500/api/user/userListenProcess/updateListenProcess

	@TingshuLogin
	@Operation(summary = "更新MongoDb中用户声音的播放进度")
	@PostMapping("/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
		userListenProcessService.updateListenProcess(userListenProcessVo);
		return Result.ok();
	}

	//Request URL: http://localhost:8500/api/user/userListenProcess/getLatelyTrack
	@GetMapping("/getLatelyTrack")
	@TingshuLogin
	@Operation(summary = "用户听最近一次的专辑的声音")
	public Result getLatelyTrack(){
		Map<Object,Object> map = userListenProcessService.getLatelyTrack();
		return Result.ok(map);
	}

}

